global
  log         127.0.0.1 local0
  log         127.0.0.1 local1 notice
  maxconn     20000
  daemon
  spread-checks 2

defaults
  mode                    http
  log                     global
  option                  tcplog
  option                  dontlognull
  option http-server-close
  option                  redispatch
  timeout http-request    2s
  timeout queue           3s
  timeout connect         1s
  timeout client          1h
  timeout server          1h
  timeout http-keep-alive 1h
  timeout check           2s
  maxconn                 18000 

backend stats-back
  mode http
  balance roundrobin
  stats uri /haproxy/stats
  stats auth pxcstats:secret

frontend stats-front
  bind *:8081
  mode http
  default_backend stats-back

{% for s in servers | d([], true) | list %}
frontend {{ s.name }}
  bind *:{{ s.port + 1 }}
  mode tcp
  tcp-request inspect-delay 5s
  #tcp-request content reject if !HTTP
  tcp-request content accept if { req.ssl_hello_type 1 }
  default_backend {{ s.name }}

backend {{ s.name }}
  mode tcp
  option tcp-check
  balance roundrobin
  default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
  {% for ip in s.ips %}
  server {{ s.name }}{{ loop.index }} {{ ip }}:{{ s.port }} check
  {% endfor %}

{% endfor %}
